package com.ctsi.ssdc.controller;

import com.ctsi.ssdc.entity.Excel09;
import com.ctsi.ssdc.service.Excel09Service;
import com.ctsi.ssdc.service.ExcelService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.web.PageableDefault;
import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 11基础表投资（工投基础）(Excel09)表控制层
 *
 * @author makejava
 * @since 2023-03-15 16:38:20
 */
@RestController
@RequestMapping("excel/09")
public class Excel09Controller {
    /**
     * 服务对象
     */
    @Resource
    private Excel09Service excel09Service;
    @Resource
    private ExcelService excelService;

    /**
     * 分页查询
     *
     * @param excel09 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @GetMapping
    public ResponseEntity<Page<Excel09>> queryByPage(Excel09 excel09,@PageableDefault(page = 0, size = 50) Pageable pageRequest) {
        return ResponseEntity.ok(this.excel09Service.queryByPage(excel09,(PageRequest) pageRequest));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    @Transactional(rollbackFor = Exception.class)
    public ResponseEntity<Excel09> queryById(@PathVariable("id") Long id) {
        Excel09 res = this.excel09Service.queryById(id);
        return ResponseEntity.ok(res);
    }

    /**
     * 新增数据
     *
     * @param excel09 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<Excel09> add(Excel09 excel09) {
        return ResponseEntity.ok(this.excel09Service.insert(excel09));
    }

    /**
     * 编辑数据
     *
     * @param excel09 实体
     * @return 编辑结果
     */
    @PutMapping
    @Transactional(rollbackFor = Exception.class)
    public ResponseEntity<Excel09> edit(Excel09 excel09) {
        ResponseEntity<Excel09> update = ResponseEntity.ok(this.excel09Service.update(excel09));
        excelService.sheet9Cal(excel09.getStatisticalTime());
        return update;
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(Long id) {
        return ResponseEntity.ok(this.excel09Service.deleteById(id));
    }

}

